<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<HTML>
<HEAD>
<META HTTP-EQUIV="content-type" content="text/html;charset=ISO-8869-1">
<TITLE>QP/lwIP--CGI Demo</TITLE>
<LINK href="style.css" type=text/css rel=Stylesheet>
<LINK rel="icon" href="img/favicon.ico" type="image/x-icon" />
</HEAD>

<BODY>
<TABLE cellSpacing=0 cellPadding=0 width="100%" border="0">
  <TR>
    <TD id=masthead noWrap align=left><A href="http://www.state-machine.com"><IMG
      src="img/logo_ql.jpg"
      title="Quantum Leaps - innovating embedded systems"
      alt="Quantum Leaps - innovating embedded systems"
      style="padding-bottom:5px;"></A>
    </TD>
    <TD width="100%"></TD>
    <TD nowrap>
    <B>Quantum Leaps, LLC</B><br>
    <A HREF="mailto:info@state-machine.com">info@state-machine.com</A><br>
    <A HREF="http://www.state-machine.com">www.state-machine.com</A>
    </TD>
  </TR>
  <TR>
    <TD id="menu" colspan="3" noWrap align=left bgcolor="#000099" height="25">
      <BIG>&nbsp;&nbsp;<A HREF="index.htm">HOME</A>&nbsp;&nbsp; |
           &nbsp;&nbsp;<A HREF="ssi_demo.shtm">SSI DEMO</A>&nbsp;&nbsp; |
           &nbsp;&nbsp;<B>CGI DEMO</B>&nbsp;&nbsp; |
           &nbsp;&nbsp;<A HREF="udp_demo.htm">UDP DEMO</A></BIG>
    </TD>
  </TR>
</TABLE>

<!--  BEGIN_CONTENT -->
<A NAME="About"></A>
<H1>About CGI Support</H1>

<A HREF="http://www.state-machine.com/lwip" TARGET="_blank"><IMG SRC="img/logo_lwip_qp.jpg" ALT="QP-lwIP" align="left" hspace="10" vspace="5"></A>

<P>The HTTP server that comes with <strong>lwIP</strong> has been extended to support rudimentary <strong>Common Gateway Interface (CGI)</strong> facility. To enable the CGI support in the <strong>lwIP-HTTP</strong> server, you need to define the macro <CODE>INCLUDE_HTTPD_CGI</CODE> in the <CODE>lwipopts.h</CODE> header file. You must also provide the mapping between CGI requests (strings) and CGI callback functions and register this mapping by calling the <CODE>http_set_cgi_handlers()</CODE> function.
</P>

<A HREF="http://www.state-machine.com/lwip/AN_QP_and_lwIP.pdf" TARGET="_blank"><IMG SRC="img/AN_QP_and_lwIP.jpg" ALT="Application Note (1.4MB PDF)" align="right" hspace="10" vspace="5"></A>

<P>The CGI implemented in the <strong>lwIP-HTTP</strong> works currently only with the GET method, which encodes all parameters within the URI rather than in a block following the request. Attempts to use the POST method will result in the request being ignored.
</P>
<P>After receiving a CGI request, the <strong>lwIP-HTTP</strong> server will scan all registered requests (strings) and call the corresponding CGI callback function, if the match is found. The <strong>lwIP-HTTP</strong> server will also parse the CGI request parameters and will pass them to the CGI callback function. Currently the maximum number of CGI parameters cannot exceed 16, but you can re-define this limit by changing the macro <CODE>MAX_CGI_PARAMS</CODE> in the <CODE>http.h</CODE> header file.
<P>
<P>Please refer to the Quantum Leaps Application Note: <A HREF="http://www.state-machine.com/lwip/AN_QP_and_lwIP.pdf" TARGET="_blank">"QP and lwIP TCP/IP Stack"</A> for more information. The Application Note in PDF is provided in the QP-lwIP example code.
</P>

<A NAME="Example"></A>
<H1>CGI Example</H1>

<P>The following form demonstrates sending commands to your embedded target via the <strong>lwIP-HTTP</strong> server. The form contains a text control, which allows you to type some text to be displayed on the screen in the target board. You send the command by pressing the <strong>Submit</strong> button. In response, the <strong>lwIP-HTTP</strong> server will execute the command in the target and will serve the <CODE>thank_you.htm</CODE> page.
</P>

<form name="CGI Example" method="GET" action="display.cgi">
<table summary="cgi example" width="95%" cellspacing=4 cellpadding=1 align="center" valign="middle">
  <tr align="left">
    <td colspan="2" bgcolor="#ffff66" align="center"><b>CGI Example</b>
    </td>
  </tr>
  <tr bgcolor="#e0e0e0" align="left">
    <td width="150px">&nbsp;&nbsp;Screen text:&nbsp;
    </td>
    <td>
      &nbsp; <input type="text" name="text" size="10" maxlength="10">&nbsp;
        <input type="submit" name="submit" value="Submit" ><br>
    </td>
  </tr>
</table>
</form>
<br />

<div id="footer">
<p>&copy; 2002-2011 Quantum Leaps - All Rights Reserved&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;103 Cobble Ridge Drive, Chapel Hill, NC 27516, USA<br />
Toll-free: 866.450.LEAP&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;Direct: 919.360.5668&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;Fax: 919.869.2998&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;<a href="mailto:info@quantum-leaps.com">info@quantum-leaps.com</a></p>
</div> <!-- id="footer" -->


</BODY>
</HTML>
